package  ${package}.dto.converter;

import ${package}.dto.${table.className}DTO;
import ${package}.entity.${table.className}Entity;
import java.util.List;
import java.util.Objects;
import java.util.stream.Collectors;

/**
* Created by Administrator on 2018/11/27.
*/
public class ${table.className}Converter {
private ${table.className}Converter() {
// do nothing
}
/**
* Entity对象转换为DTO对象
*
* @param ${table.className?uncap_first} DO对象
* @return DTO对象
*/
public static ${table.className}DTO toDTO(${table.className}Entity ${table.className?uncap_first}) {
    if (Objects.isNull(${table.className?uncap_first})) {
        return null;
    }
    ${table.className}DTO result = new  ${table.className}DTO();
    <#list table.columns as column>
        <#if column.sqlName == "VERSION_NO">
        result.setVersionNO(${table.className?uncap_first}.getVersionNO());
        <#else>
        result.set${column.javaProperty?cap_first}(${table.className?uncap_first}.get${column.javaProperty?cap_first}());
        </#if>

    </#list>
    // TODO
   return result;
}

/**
* DTO对象转换为Entity对象
*
* @param ${table.className?uncap_first} DO对象
* @return VO对象
*/
public static ${table.className}Entity toEntity(${table.className}DTO ${table.className?uncap_first}) {
    if (Objects.isNull(${table.className?uncap_first})) {
        return null;
    }
    ${table.className}Entity result = new  ${table.className}Entity();
    <#list table.columns as column>
         result.set${column.javaProperty?cap_first}(${table.className?uncap_first}.get${column.javaProperty?cap_first}());
    </#list>
    // TODO
    return result;
}

/**
* DTO对象转换为DO对象
*
* @param ${table.className?uncap_first} DO对象
* @return VO对象
*/
public static ${table.className}Entity toEntity(${table.className}Entity result,${table.className}DTO ${table.className?uncap_first}) {
if (Objects.isNull(${table.className?uncap_first})) {
return null;
}
<#list table.columns as column>
    <#if column.primaryKey>

    <#else>
    result.set${column.javaProperty?cap_first}(${table.className?uncap_first}.get${column.javaProperty?cap_first}());
    </#if>
</#list>
// TODO
return result;
}

/**
* 批量 Entity对象转换为DTO对象
*
* @param ${table.className?uncap_first}List Entity集合对象
* @return DTO对象
*/
public static List< ${table.className}DTO> toDTO(List< ${table.className}Entity> ${table.className?uncap_first}List) {
    if (Objects.isNull(${table.className?uncap_first}List)) {
       return null;
    }
      return ${table.className?uncap_first}List.stream().map(${table.className}Converter::toDTO).collect(Collectors.toList());
    }

}
